package com.ding.lock8;

import java.util.concurrent.TimeUnit;

/**
 * @author ding
 * @date 2021/7/17 19:44
 * 一个静态的同步方法，一个普通的同步方法
 */


public class Test4 {
    public static void main(String[] args) {
        Phone4 phone1 = new Phone4();
        Phone4 phone2 = new Phone4();
        new Thread(() -> {
            phone1.sendSms();
        }, "A").start();
        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        new Thread(() -> {
            phone2.call();
        }, "B").start();
    }


}

class Phone4 {

    //静态的同步方法
    public static synchronized void sendSms() {
        try {
            TimeUnit.SECONDS.sleep(4);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("发短信");
    }

    //普通的同步方法
    public synchronized void call() {
        System.out.println("打电话");
    }
}